<?php
header( 'Content-Type:application/json; charset=utf-8' );
session_start();
if ( empty( $_SESSION[ 'userinfo' ] ) ) {
    $result = [
        'code' => '403',
        'msg' => '未登录，请登录',
    ];
    echo json_encode( $result );
    exit ;
}
$input = file_get_contents( 'php://input' );
$arr = json_decode( $input, true );
$sub_id = $arr[ 'sub_id' ] ?? '';
$sub_eval = $arr[ 'sub_eval' ] ?? '';
$sub_score = $arr[ 'sub_score' ] ?? '';

$dbms = 'mysql';
$host = '127.0.0.1';
$dbName = 'g09short';
$user = 'root';
$pass = 'G09short.';
$dsn = "$dbms:host=$host;dbname=$dbName";

try {
    $dbh = new PDO( $dsn, $user, $pass );
    $sql = "UPDATE zyh_submit  SET sub_eval = '" . $sub_eval . "',sub_score = '" . $sub_score . "' WHERE sub_id  = '" . $sub_id . "';";
    $stmt = $dbh->exec( $sql );
    $result = [
        'code' => '200',
        'msg' => '更新成功！',
        'data' => $stmt
    ];

    $dbh = null;

    echo json_encode( $result );
} catch ( PDOException $e ) {
    $result = [
        'code' => '500',
        'msg' => '$e->getMessage()',
    ];
    die( $result );
}
?>